package loengud.w08;

import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * Convert Applet to application.
 * The first thing we change is instead of
 * ".. extends Applet" we use ".. extends JPanel".
 * @author Ago
 *
 */
public class AppletToApplication extends JPanel {
	
	/**
	 * We add the main method, which is
	 * executed when the program is launched.
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 * In order to show our panel,
		 * we need a top-level component (like JFrame).
		 * We create a new JFrame and add
		 * our panel (current class) into it.
		 */
		JFrame f = new JFrame("applet to app");
		JPanel panel = new AppletToApplication();
		f.getContentPane().add(panel);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setSize(300, 200);
		f.setVisible(true);
	}
	
	/**
	 * We override paintComponent method for 
	 * the given panel. Originally, for the Applet
	 * we used "paint" method, so the name here
	 * is changed.
	 * @param g Graphics object 
	 */
	@Override
	public void paintComponent(Graphics g) {
		g.drawString("Hello World!", 10, 30);
	}

}
